/**
 * Created by zhaojm on 15/3/21.
 */
// 坚果
game.PineCone = frame.BaseRole.extend({


    _action_roll : null,


    ctor:function(){
        this._super();
        this._className = 'game.PineCone';

        this._action_roll = new cc.RepeatForever(new cc.Animate(
            new cc.Animation([0, 1, 2, 3, 4, 5].map(function (i) {
                return cc.spriteFrameCache.getSpriteFrame("pinecone/" + i + ".png");
            }), 0.1)
        ));

        this.roll();

    },

    getNode:function(){
        return new cc.Sprite('#pinecone/0.png');
    },

    getNodeHeight:function(){
        return this._node.getContentSize().height;
    },

    update : function(dt){
        this._super(dt);

    },

    roll : function(){
        this._node.runAction(this._action_roll);
    },


    doCollidedWithHero : function(){
        //cc.log('...hero');
        if(this._layer._speedUpTimeCount <= 0) {

            var bear = this._layer._bear;
            bear.setScale(bear.getScale() - 0.1);
        }

        var hero = this._layer._hero;
        hero._pinconeCount++;

        //var effect = new game.HeroEatPineConeEffect();
        //effect.addToLayer(this._layer, hero.getPosition());
        (new game.HeroEatPineConeEffect()).addToLayer(this._layer, cc.p(hero.getPositionX(), hero._defaultY - 10));
        this.removeFromLayer();

    },

    doCollidedWithBear:function(){
        //cc.log('...bear');
        var bear = this._layer._bear;

        
        if(this._layer._speedUpTimeCount <= 0) {

            bear.setScale(bear.getScale() + 0.3);
        }
        (new game.BearEatPineConeEffect()).addToLayer(this._layer, cc.p(bear.getPositionX(), bear.getCollidedHeight() - 20), bear.getScale());
        this.removeFromLayer();
    },


});